<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>短链接和分享/转发数生成、分享/转发按钮生成机制研究</title>
<script type="text/javascript" src="js/tangram-1.3.5.core.js"></script>
<script type="text/javascript" src="js/jsonp.js"></script>
<script type="text/javascript" src="js/xUtil.js"></script>
</head>

<body>
<h1>短链接和分享/转发数生成、分享/转发按钮生成机制研究</h1>

<div id="main">
	<div>请输入链接（请包括"http://"，否则结果将不正确）：
		<input name="longurl" id="longurl" type="text" value="" size="100" />
	</div>
	<div>
		<input name="submitsearch" id="submitsearch" type="button" value="提交批量生成" />
	</div>
	<hr />
	
	<div>
		<a href="http://open.t.sina.com.cn/sharebutton" target="_blank">新浪微博转发按钮</a>：<span id="sina_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://widget.renren.com/?widget=freeshare" target="_blank">人人网自由分享按钮</a>：<span id="renrenshare_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://connect.open.sdo.com/connect/button/" target="_blank">盛大网喜欢按钮</a>：<span id="sdo_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://widget.renren.com/?widget=like" target="_blank">人人网喜欢按钮</a>：<span id="renren_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://open.t.qq.com/apps/share/explain.php" target="_blank">腾讯微博转播按钮</a>：<span id="txweibo_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://open.t.sohu.com/en/%E4%B8%80%E9%94%AE%E5%88%86%E4%BA%AB%E5%88%B0%E6%90%9C%E7%8B%90%E5%BE%AE%E5%8D%9A" target="_blank">搜狐微博一键分享按钮</a>：<span id="sohut_iframe">null</span>
	</div>
	<br />
	
	<div>
		<a href="http://open.t.163.com/" target="_blank">网易微博一键分享按钮</a>：<span id="163t_iframe">目前找不到，请有心人提供</span>
	</div>
	<br />
	
</div>

<div id="side">
	<ul>
		<li>本工具仅用于各种开放平台下的短链接生成和分享/转发按钮生成机制的研究，用于其它用途本人一概不负责任。</li>
		<li>本工具采取JS操作，故移动设备不能使用此工具；并且可能出现网络不稳定而导致无法使用的情况。</li>
		<li>本工具目前比较完美支持FireFox和Chrome，IE下有时候会出问题。</li>
		<li><a href="index.html">返回新浪短链接生成器（JSONP版本）。</a></li>
		<li>觉得此工具对你的研究有帮助？<a href="javascript:xController.sina.openShareWindow('http://surl.sinaapp.com/index_research.html', '各开放平台分享数和转发/分享按钮生成机制研究：', '');">推荐给朋友吧！</a></li>
	</ul>
</div>


<div id="footer">
	<div id="debugTxt" style="color:blue;"></div>
	<hr />
	<div id="footer_link">
	Javascript:&nbsp;<a href="http://tangram.baidu.com/" target="_blank">百度Tangram js</a>
	&nbsp;|&nbsp;云计算服务商:&nbsp;<a href="http://sae.sina.com.cn" target="_blank"><img src="http://static.sae.sina.com.cn/image/poweredby/117X12px.gif" title="Powered by Sina App Engine" /></a>
	<br />最后更新:&nbsp;[SVN]$Date: 2011-04-09 08:26:55 +0000 (Sat, 09 Apr 2011) $&nbsp;$Rev: 184 $
	&nbsp;|&nbsp;Created By Horse Luke
	</div>
</div>

<script>
var xController =  {};
var xModel =  {};

xController.front = {};

xController.front.submit = function(){
	xUtil.debug.clearTxt();
	xUtil.debug.outputTxt(new Date() + ' 开始运行');
	var longurl = T.dom.g('longurl').value;
	if(longurl == ''){
		return xUtil.debug.outputTxt('错误：长链接不能为空！', true);
	}
	xController.buttonMaker.makeSina(longurl);
	xController.buttonMaker.makeRenrenLike(longurl);
	xController.buttonMaker.makeRenrenShare(longurl);
	xController.buttonMaker.makeSdoLike(longurl);
	xController.buttonMaker.makeTencentWeibo(longurl);
	xController.buttonMaker.makeSohuWeibo(longurl);
	xUtil.debug.outputTxt(new Date() + '全部运行完毕');
};

xController.buttonMaker = {};

xController.buttonMaker.makeSina = function(longurl){
	var sina_url = 'http://hits.sinajs.cn/A1/weiboshare.html?url=' + longurl + '&count=1&appkey=&type=4';
	xUtil.debug.outputTxt('新浪微博的转发按钮生成iframe地址是：' + sina_url);
	xController.buttonMaker.makeIframe(sina_url, 142, 66, 'sina_iframe');
};

xController.buttonMaker.makeTencentWeibo = function(longurl){
	xUtil.debug.outputTxt('目前腾讯微博并没有使用iframe形式。');
	var html = '<a href="http://v.t.qq.com/share/share.php?url='+ encodeURIComponent(longurl) +'&appkey=' + encodeURI('appkey') + '" target="_blank" class="tmblog"><img src="http://v.t.qq.com/share/images/s/b32.png" /></a>';
	document.getElementById('txweibo_iframe').innerHTML = html;
};

xController.buttonMaker.makeSohuWeibo = function(longurl){
	xUtil.debug.outputTxt('目前sohu微博并没有使用iframe形式。');
	var html = '<a href="http://t.sohu.com/third/post.jsp?&url='+ encodeURIComponent(longurl) +'&title=&content=utf-8&pic=" target="_blank"  style="margin:0 0 0 20px;font-size:12px;font-family:\'\5b8b\4f53\';color:#369"><span style="display:inline-block;width:16px;height:16px;margin:0 3px 0.2em -20px;vertical-align:middle;background:url(http://s2.cr.itc.cn/img/t/152.png) no-repeat"></span>分享到搜狐微博</a>';
	document.getElementById('sohut_iframe').innerHTML = html;
};

xController.buttonMaker.makeRenrenLike = function(longurl){
	var renren_url = 'http://www.connect.renren.com/like?url=' + encodeURIComponent(longurl);
	xUtil.debug.outputTxt('人人喜欢的按钮生成iframe地址是：' + renren_url);
	xController.buttonMaker.makeIframe(renren_url, 142, 66, 'renren_iframe');
};

xController.buttonMaker.makeRenrenShare = function(longurl){
	xController.XN.appendCss();
	xUtil.debug.outputTxt('人人自由分享的按钮是插入一段js后，通过js进行渲染的。本页面跳过渲染步骤，主要侧重于分享数的获取');
	document.getElementById('renrenshare_iframe').innerHTML = xController.XN.createShareHtml(longurl);
	xController.XN.runCountJsonp(longurl);
};

xController.buttonMaker.makeSdoLike = function(longurl){
	var sdo_url = 'http://api.connect.open.sdo.com/like?appid=700040900&size=2&color=blue&title=&link=' + encodeURIComponent(longurl) +'&type=&pic=&desc=&counter=&data=0';
	xUtil.debug.outputTxt('盛大喜欢的按钮比较复杂，插入的不是标准的html代码，必须通过js引用才生效，这里是js最终生成的iframe地址是：' + sdo_url);
	xController.buttonMaker.makeIframe(sdo_url, 155, 26, 'sdo_iframe');
};

xController.buttonMaker.makeIframe = function(url, width, height, id){
	var html = '<iframe width="' + width + '" height="' + height + '" src="' + url + '" frameBorder="0" scrolling="no" allowTransparency="allowtransparency">';
	document.getElementById(id).innerHTML = html;
};

xController.sina = {};
xController.sina.openShareWindow = function(url, title, appkey){
	window.open('http://service.t.sina.com.cn/share/share.php?url=' + url + '&appkey=' + appkey + '&title=' + encodeURIComponent(title), '_blank','width=615,height=505');
};

xController.XN = {};
xController.XN.ShareCss = 0;
xController.XN.static_url = "http://s.xnimg.cn/connect";
xController.XN.connect_url = "http://www.connect.renren.com";
xController.XN.appendCss = function(){
	if(xController.XN.ShareCss == 1){
		return ;
	}
    var b = document.createElement("link");
    b.rel = "stylesheet";
    b.type = "text/css";
    b.href = xController.XN.static_url + "/css/share_button.css";
    xUtil.common.insertdom(b);
    xUtil.debug.outputTxt('人人自由分享的CSS已经加载完毕');
	xController.XN.ShareCss = 1;
};

xController.XN.createShareHtml = function(url){
	return '<a href="' + xController.XN.connect_url + '/share/sharer?url=' + encodeURIComponent(url) +'&title=" type="button_count_top_large" name="xn_share" style="text-decoration: none;" target="_blank"><span class="xn_share_wrapper xn_share_right"><span class="xn_share_large"><span class="xn_share_button"><span class="xn_share_button_head"></span><span class="xn_share_label">分享到人人</span><span class="xn_share_button_end"></span></span><span class="xn_share_count_nub "></span><span class="xn_share_counter " id="xn_share_counter">0</span></span></span></a>';
};

xController.XN.runCountJsonp = function(surl){
	var url = xController.XN.connect_url + '/share/linksCounter?urls=' + encodeURIComponent(surl) + '&format=json&callback=XN.Share.Counter.onFetchData';
	//xUtil.debug.outputTxt('开始载入JSONP：' + url);
	xUtil.debug.outputTxt('xController.XN.runCountJsonp 开始载入JSONP');
	jsonp(url,
		    null,
		    function(){
				xUtil.debug.outputTxt(new Date() + ' xController.XN.runCountJsonp载入JSONP超时！', true);
	    	},
		    function(){
	    		xUtil.debug.outputTxt(new Date() + ' xController.XN.runCountJsonp载入JSONP失败！', true);
			},
		    function(){
	    		xUtil.debug.outputTxt(new Date() + ' xController.XN.runCountJsonp载入JSONP成功！');
			}
	);
};

if (!window.XN) {
    window.XN = {}
}
if (!window.XN.Share) {
    XN.Share = {};
    XN.Share.Counter = {
        onFetchData: function(data) {
            try{
            	var debugTxt = 'JSONP运行成功！得到人人分享数：' + data[0].share_count;
            	xUtil.debug.outputTxt(debugTxt);
        	    T.dom.g('xn_share_counter').innerHTML = xUtil.common.beautyNum(data[0].share_count);
            }catch(e){
            	xUtil.debug.outputTxt(new Date() + ' XN.Share.Counter.onFetchData运行失败！错误描述：' + e.description, true);
            }
        }
    };
};

T.event.on("submitsearch", "click", function(event){xController.front.submit();});
</script>

</body>
</html>